package user;

import beans.SessionManagedBean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import lecture.Lecture;
import task.TaskCategory;

/**
 *
 * @author Thorsten Ludwig
 */

@Entity
public class ScoreGroup implements Serializable {
    @Id
    private Long id;

    
    @OneToOne
    private Lecture lecture;
    
    @OneToMany
    private List<TaskCategory> categorys;
    
    
    @OneToMany
    private List<User> users;
    
    private String name;
    
    public ScoreGroup() {
        FacesContext c = FacesContext.getCurrentInstance();
        SessionManagedBean sb = c.getApplication().evaluateExpressionGet(c, "#{sessionBean}", SessionManagedBean.class);
        Lecture lecture = sb.getLectureBean().getLecture();
        this.lecture = lecture;
        this.users = new ArrayList<User>();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Lecture getLecture() {
        return lecture;
    }

    public void setLecture(Lecture lecture) {
        this.lecture = lecture;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public void addUser(User u) {
        this.users.add(u);
    }
    
    public void removeUser(User u) {
        this.users.remove(u);
    }

    public List<TaskCategory> getCategorys() {
        return categorys;
    }

    public void setCategorys(List<TaskCategory> categorys) {
        this.categorys = categorys;
    }

    public List<User> getUsers() {
        return users;
    }
}
